package dto

type PageVo struct {
	PageNo int `json:"pageNo" default:"1"`
	PageSize int `json:"pageSize" default:"10"`
}

type Page[Element any] struct {
	List []Element `json:"list"`

	PageNo int `json:"pageNo" default:"1"`
	PageSize int `json:"pageSize" default:"10"`
	TotalElements int `json:"totalElements"`
	TotalPage int `json:"totalPage"`
}

func NewPage[Element any](list []Element, totalElements int,pageVo *PageVo) *Page[Element]{
	var totalPage int
	if totalElements%pageVo.PageSize == 0{
		totalPage = totalElements/pageVo.PageSize
	}else{
		totalPage = totalElements/pageVo.PageSize+1
	}
	ret := Page[Element]{
		List: list,
		PageNo: pageVo.PageNo,
		PageSize: pageVo.PageSize,
		TotalElements: totalElements,
		TotalPage: totalPage,
	}
	return &ret
}